Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "radek stromský"

It would be enough to add support for projection for FirstOrDefaultAsync and GetAllListAsync. That should cover most of the scenarios. Overload would cause a problems, so designed the interface methods like this:

Task<TModel> QueryFirstOrDefaultAsync<TModel>(Func<IQueryable<TEntity>, IQueryable<TModel>> projection);
Task<List<TModel>> QueryToListAsync<TModel>(Func<IQueryable<TEntity>, IQueryable<TModel>> projection);

Usage example:

var result = await _myRepo.QueryFirstOrDefaultAsync(q =>  q.Where(x => x.Id == id).ProjectTo<MyDto>());

or without using AutoMapper's IQuerable extension:

var result = await _myRepo.QueryFirstOrDefaultAsync(q =>  q.Where(x => x.Id == id).Select(x => x.Status));

Such implementation for EF repository is quite straightforward. Not sure about NHibernate.

What is your opinion on this?

PS: I can contribute if we agree on this solution. I am also opened to any suggestions how should final method names look like.

Problem solved!

My base controller class wan't abstract. When I changed it to abstract, log record for controller's proxy is no longer saved to database.

I don't know when OData is done with IQueryable either. Only working solution I can think of is disposing DbContext inside Dispose(bool) method of the controller. That is what I am doing now. But I don't like an idea of using DbContext inside WebApi project instead of repositories.

Unfortunately this doesn't fix the problem. DbContext is still disposed before ODataController is able to apply query options to IQueryable object.

InvalidOperationException: The operation cannot be completed because the DbContext has been disposed.

Showing 1 to 4 of 4 entries